package cn.wolfcode.rbac.service.report_statistics.impl;

import cn.wolfcode.rbac.mapper.report_statistics.CustomerReportMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.report_statistics.ICustomerReportService;
import cn.wolfcode.rbac.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service
public class ICustomerReportServiceImpl implements ICustomerReportService{
    @Autowired
    private CustomerReportMapper customerReportMapper;

    public ICustomerReportServiceImpl() {
    }

//    public PageInfo selectCustomerReport(QueryObject qo) {
//        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
//        List<Map> list = this.customerReportMapper.selectCustomerReport(qo);
//        return new PageInfo(list);
//    }

    public List<Map> listAll(QueryObject qo) {
        return this.customerReportMapper.selectCustomerReport(qo);
    }
    @Override
    public PageResult query(QueryObject queryObject) {

        int count = customerReportMapper.selectForCount(queryObject);
       // System.out.println(count);
        if(count == 0){
            // 1.如果数据库中没有数据是不需要分页显示，直接返回一个空数据
            return new PageResult(1,3, Collections.emptyList(),0);
        }else {
            // 2.如果数据库中有数据就要分页显示
            List<Map> customersMap = customerReportMapper.selectCustomerReport(queryObject);
            return new PageResult(queryObject.getCurrentPage(),queryObject.getPageSize(),customersMap,count);
        }
       // return null;
    }

}
